package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

  @Autowired
  private BedService bedService;

  @GetMapping("/read/room/{roomId}")
  @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
  public ResponseResult<List<BedVo>> readBedByRoomId(@ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
    List<BedVo> beds = bedService.getBedsByRoomId(roomId);
    return success(beds);
  }

  @PostMapping("/create")
  @ApiOperation(value = "创建床位")
  public ResponseResult addBed(@RequestBody BedDto bed) {
    bedService.addBed(bed);
    return success();
  }

  @GetMapping("/read/{id}")
  @ApiOperation(value = "")
  public ResponseResult<BedVo> getById(@PathVariable("id") Integer id ) {

    return success(bedService.getById(id));
  }
  @PutMapping("/update")
  @ApiOperation(value = "")
  public ResponseResult<BedVo> update(@RequestBody BedDto bed ) {
    bedService.update(bed);
    return success();
  }
  @DeleteMapping("/delete/{id}")
  @ApiOperation(value = "")
  public ResponseResult<BedVo> delete(@PathVariable("id") Long id) {
    bedService.delete(id);
    return success();
  }

}
